﻿<navigation:Page x:Class="RialternativeSample.Views.EmployeesView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                 xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                 xmlns:converters="clr-namespace:RialternativeSample.Client.Converters"
                 mc:Ignorable="d"
                 xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
                 xmlns:s="clr-namespace:FirstLook.ServiceModel.DomainServices.Client.Security;assembly=FirstLook.ServiceModel.DomainServices.Client.Security"
                 d:DesignWidth="640"
                 d:DesignHeight="480"
                 Title="Employees"
                 Style="{StaticResource PageStyle}"
                 s:Authorization.RequiresAuthentication="True"
                 DataContext="{Binding EmployeesViewModel, Source={StaticResource ViewModelLocator}}">
    <navigation:Page.Resources>
        <CollectionViewSource x:Key="employeesCollection"
                              Source="{Binding Employees}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Employees2" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
        <CollectionViewSource x:Key="employeeTerritoriesCollection"
                              Source="{Binding CurrentItem.EmployeeTerritories, Source={StaticResource employeesCollection}}" />
        <converters:TrimConverter x:Key="TrimConverter" />
    </navigation:Page.Resources>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <sdk:DataGrid ItemsSource="{Binding Source={StaticResource employeesCollection}}"
                          IsReadOnly="True"
                          Margin="0,0,0,15"
                          AutoGenerateColumns="False">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Header="Last name"
                                            Binding="{Binding LastName}" />
                    <sdk:DataGridTextColumn Header="First name"
                                            Binding="{Binding FirstName}" />
                    <sdk:DataGridTextColumn Header="Title"
                                            Binding="{Binding Title}" />
                    <sdk:DataGridTextColumn Header="City"
                                            Binding="{Binding City}" />
                    <sdk:DataGridTextColumn Header="Home phone"
                                            Binding="{Binding HomePhone}" />
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>
            <sdk:GridSplitter VerticalAlignment="Bottom"
                              HorizontalAlignment="Stretch" />
            <toolkit:HeaderedContentControl HorizontalContentAlignment="Stretch"
                                            Grid.Row="1"
                                            Margin="0,10,0,0">
                <toolkit:HeaderedContentControl.Header>
                    <TextBlock Text="Territories"
                               FontSize="16"
                               FontWeight="Bold" />
                </toolkit:HeaderedContentControl.Header>
                <Grid>
                    <StackPanel Orientation="Horizontal"
                                HorizontalAlignment="Right">
                        <TextBlock Text="Region : "
                                   FontSize="12"
                                   FontWeight="Bold" />
                        <TextBlock Text="{Binding CurrentItem.Territory.Region.RegionDescription, Source={StaticResource employeeTerritoriesCollection}, Converter={StaticResource TrimConverter}}" />
                    </StackPanel>
                    <sdk:DataGrid IsReadOnly="True"
                                  Margin="0,20,0,0"
                                  AutoGenerateColumns="False"
                                  ItemsSource="{Binding Source={StaticResource employeeTerritoriesCollection}}">
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTextColumn Header="Id"
                                                    Binding="{Binding TerritoryID}" />
                            <sdk:DataGridTextColumn Header="Description"
                                                    Binding="{Binding Territory.TerritoryDescription, Converter={StaticResource TrimConverter}}" />
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>
                </Grid>
            </toolkit:HeaderedContentControl>
        </Grid>
</navigation:Page>
